<%@include file="/WEB-INF/pages/commons/commons.jsp" %>
<%@page import="org.apache.shiro.SecurityUtils"%>

<stripes:layout-render name="${_themePath}/basic-dashboard-layout.jsp" _title="Dashboard">

    <stripes:layout-component name="_head">
        <c:out value="${_head}" escapeXml="false" />
        <meta name="_uniquePageId_" content="_dashboard_"/>
        <script type="text/javascript">
                // === spaceHeaderMenu
                YAHOO.util.Event.onContentReady("dashboardHeaderMenu", function() {
                    var manageHeaderMenu = new YAHOO.widget.Button("dashboardHeaderMenuButton",
                                            { type: "menu", menu: "dashboardHeaderMenuButtonSelect" });
                    //	"click" event listener for the second Button's Menu instance
                    var onMenuClick = function (p_sType, p_aArgs) {
                        var oEvent = p_aArgs[0];	//	DOM event
                        var oMenuItem = p_aArgs[1];	//	MenuItem instance that was the
                                                    //	target of the event
                        if (oMenuItem) {
                            if ('0' == oMenuItem.value) {   // Add Space
                                document.location.href = '<stripes:url beanclass="foo.bar.wiki.web.action.space.AddSpaceActionBean" event="view"/>';
                            }
                            else {
                                alert('unrecognized menu option');
                            }
                        }
                    };
                    //	Add a "click" event listener for the Button's Menu
                    manageHeaderMenu.getMenu().subscribe("click", onMenuClick);
                });
        </script>
    </stripes:layout-component>


    <stripes:layout-component name="_topNav">
        <H1>Dasboard</H1>
        <UL class="gc-topnav-tabs">
            <LI>&nbsp;
                <jsecurity:hasPermission name="space:addSpace:*">
                    <span id="dashboardHeaderMenu">
                    <input type="button" id="dashboardHeaderMenuButton" value="Options"/>
                    <select id="dashboardHeaderMenuButtonSelect">
                        <option value="0">Add Space</option>
                    </select>
                    </span>
                </jsecurity:hasPermission>
            </LI>
        </UL>
    </stripes:layout-component>


    <stripes:layout-component name="_leftContent">

        <h2>Information</h2>
        <p>
           FooBarWiki is a simple wiki designed to make it easy for you and your team to share
           information with each other, and with the world.
        </p>
        <p>
           This is the default installation of FooBarWiki. The space 'FooBarWikiDocs' contains the
           documentation for FooBarWiki. You can read and add comments in 'FooBarWikiDocs' space,
           but write-access is limited. You can create a space where you'll be to do anything to it
           itself and those who you granted permission too as well. To try out FooBarWiki yourself, please
           have a look at our installation guide, download a copy and try it out locally. 
        </p>
        <p>
           The code is hosted at google code. Please log a ticket to us if there's any issue, upgrade
           or enhancement as you feel appropriate and we'll look into it as soon as possible.
        </p>
        <p>
           FooBarWiki is released under Apache License 2.0.
        </p>
        <p/>
        <p/>

        <h2>Spaces</h2>
        <p>
            This is a listing of all the spaces avaiable in this FooBarWiki installation. Each space can be
            considered as a mini-wiki which itself consists of pages. 
        </p>
        <p/>
        <p/>

        <stripes:useActionBean
                var="dashboardActionBean_listSpaces"
                executeResolution="false"
                alwaysExecuteEvent="true"
                validate="true"
                beanclass="foo.bar.wiki.web.action.general.DashboardActionBean"
                event="listSpaces"/>
        <stripes:url var="url" beanclass="foo.bar.wiki.web.action.general.DashboardActionBean" event="view">
            <stripes:param name="paginationListName" value="listSpaces"/>    
        </stripes:url>
        <div id="spacesTableDiv">
        <displaytag:table id="spacesTableElement" name="${dashboardActionBean_listSpaces.spaces}"
                                  sort="external"
                                  style="width:100%;"
                                  excludedParams="*"
                                  defaultsort="1"
                                  defaultorder="ascending"
                                  requestURI="${url}"
                                  requestURIcontext="true" >
                    <displaytag:column property="name" sortable="false" sortName="username" title="Name" />
                    <displaytag:column property="description" sortable="false" sortName="emailAddress" title="Description" />
                    <displaytag:column title="Actions">
                        <jsecurity:hasPermission name="space:viewSpaceAsWiki:${spacesTableElement.id}">
                        <stripes:link class="_view" beanclass="foo.bar.wiki.web.action.space.SpaceActionBean" event="view" name="space_view_${spacesTableElement.name}">
                            <stripes:param name="space" value="${spacesTableElement.id}"/>
                            View
                        </stripes:link>
                        </jsecurity:hasPermission>
                        <foobarwiki:hasAnyPermissions name="space:viewSpace:${spacesTableElement.id}|space:editSpace:${spacesTableElement.id}|space:removeSpace:${spacesTableElement.id}">
                        |&nbsp;<stripes:link class="_edit" beanclass="foo.bar.wiki.web.action.space.EditSpaceActionBean" event="view" name="space_manage_${spacesTableElement.name}">
                            <stripes:param name="space" value="${spacesTableElement.id}"/>
                            Manage
                        </stripes:link>
                        </foobarwiki:hasAnyPermissions>
                        <jsecurity:hasPermission name="space:removeSpace:${spacesTableElement.id}">
                        |&nbsp;<stripes:link class="_remove" beanclass="foo.bar.wiki.web.action.space.RemoveSpaceActionBean" event="remove" name="space_remove_${spacesTableElement.name}">
                            <stripes:param name="space" value="${spacesTableElement.id}"/>
                            Remove
                        </stripes:link>
                        </jsecurity:hasPermission>
                        <jsecurity:hasPermission name="space:membership:${spacesTableElement.id}">
                        |&nbsp;<stripes:link class="_membership" beanclass="foo.bar.wiki.web.action.space.EditSpaceMembershipActionBean" event="view" name="space_membership_${spacesTableElement.name}">
                            <stripes:param name="space" value="${spacesTableElement.id}"/>
                            Membership
                        </stripes:link>
                        </jsecurity:hasPermission>
                        <jsecurity:hasPermission name="space:viewSpaceAsWiki:${spacesTableElement.id}">
                        |&nbsp;<stripes:link beanclass="foo.bar.wiki.web.action.general.SpaceFeedsActionBean" event="view" name="space_rss_${spacesTableElement.name}">
                            <stripes:param name="feedType" value="rss_2_0"/>
                            <stripes:param name="space" value="${spacesTableElement.id}"/>
                            RSS
                        </stripes:link>
                        |&nbsp;<stripes:link beanclass="foo.bar.wiki.web.action.general.SpaceFeedsActionBean" event="view" name="space_atom_${spacesTableElement.name}">
                            <stripes:param name="feedType" value="atom_1_0"/>
                            <stripes:param name="space" value="${spacesTableElement.id}"/>
                            ATOM
                        </stripes:link>
                        </jsecurity:hasPermission>
                    </displaytag:column>
                </displaytag:table>
            </div>
    </stripes:layout-component>



    <stripes:layout-component name="_rightContent">
        <h2>Recent updates</h2>
        <p>
            This section lists down the pages that are either being created or modified recently.
        </p>
        <p/>
        <p/>
        <stripes:useActionBean
                var="dashboardActionBean_recentUpdates"
                executeResolution="false"
                alwaysExecuteEvent="true"
                validate="true"
                beanclass="foo.bar.wiki.web.action.general.DashboardActionBean"
                event="recentUpdates"/>
        <stripes:url var="url" beanclass="foo.bar.wiki.web.action.general.DashboardActionBean" event="view">
            <stripes:param name="paginationListName" value="recentUpdatedPages"/>
        </stripes:url>
        <div id="recentUpdateTableDiv">
        <displaytag:table id="recentUpdatesTableElement" name="${dashboardActionBean_recentUpdates.recentUpdatedPages}"
                                  sort="external"
                                  style="width:100%;"
                                  excludedParams="*"
                                  defaultsort="1"
                                  defaultorder="ascending"
                                  requestURI="${url}"
                                  requestURIcontext="true" >
                    <displaytag_el:column property="name" sortable="false" sortName="name" title="Name" />
                    <displaytag_el:column title="Modification Date">
                        <c:choose>
                            <c:when test="${not empty recentUpdatesTableElement.modificationDate}">
                                <fmt:formatDate value="${recentUpdatesTableElement.modificationDate}" pattern="dd/MM/yyyy hh:mm:ss a"/>
                            </c:when>
                            <c:otherwise>
                                <fmt:formatDate value="${recentUpdatesTableElement.creationDate}" pattern="dd/MM/yyyy hh:mm:ss a"/>
                            </c:otherwise>
                        </c:choose>
                    </displaytag_el:column>
                    <displaytag_el:column title="Actions">
                        <jsecurity:hasPermission name="space:viewPageAsWiki:${recentUpdatesTableElement.space.id}">
                        <stripes:link class="_view" beanclass="foo.bar.wiki.web.action.page.PageActionBean" event="view" name="recentUpdate_view_${recentUpdatesTableElement.name}">
                            <stripes:param name="page" value="${recentUpdatesTableElement.id}"/>
                            View
                        </stripes:link>
                        </jsecurity:hasPermission>
                        <foobarwiki:hasAnyPermissions name="space:editPage:${recentUpdatesTableElement.space.id}|space:viewPage:${recentUpdatesTableElement.space.id}|space:removePage:${recentUpdatesTableElement.space.id}">
                        |<stripes:link class="_edit" beanclass="foo.bar.wiki.web.action.page.EditPageActionBean" event="view" name="recentUpdate_manage_${recentUpdatesTableElement.name}">
                            <stripes:param name="currentPage" value="${recentUpdatesTableElement.id}"/>
                            Manage
                        </stripes:link>
                        </foobarwiki:hasAnyPermissions>
                        <jsecurity:hasPermission name="space:viewPageAsWiki:${recentUpdatesTableElement.space.id}">
                        |&nbsp;<stripes:link beanclass="foo.bar.wiki.web.action.general.PageFeedsActionBean" event="view" name="recentUpdate_rss_${recentUpdatesTableElement.name}">
                            <stripes:param name="feedType" value="rss_2_0"/>
                            <stripes:param name="page" value="${recentUpdatesTableElement.id}"/>
                            RSS
                        </stripes:link>
                        |&nbsp;<stripes:link beanclass="foo.bar.wiki.web.action.general.PageFeedsActionBean" event="view" name="recentUpdate_atom_${recentUpdatesTableElement.name}">
                            <stripes:param name="feedType" value="atom_1_0"/>
                            <stripes:param name="page" value="${recentUpdatesTableElement.id}"/>
                            ATOM
                        </stripes:link>
                        </jsecurity:hasPermission>
                    </displaytag_el:column>
                </displaytag:table>
        </div>
        <p/>
        <p/>

        
        <h2>Favourite pages</h2>
        <p>
            This section lists down your favourite pages. You can mark the pages that you are interested in as favourite
            on a page by page basis and it will appear in this list the next time you visit the Dashboard.
        </p>
        <p/>
        <p/>
        <stripes:useActionBean
                var="dashboardActionBean_favouritePages"
                executeResolution="false"
                alwaysExecuteEvent="true"
                validate="true"
                beanclass="foo.bar.wiki.web.action.general.DashboardActionBean"
                event="doFavouritePages"/>
        <stripes:url var="url" beanclass="foo.bar.wiki.web.action.general.DashboardActionBean" event="view">
            <stripes:param name="paginationListName" value="favouritePages"/>   
        </stripes:url>
        <div id="favouritePagesTableDiv">
        <displaytag:table id="favouritePagesTableElement" name="${dashboardActionBean_favouritePages.favouritePages}"
                                  sort="external"
                                  style="width:100%;"
                                  excludedParams="*"
                                  defaultsort="1"
                                  defaultorder="ascending"
                                  requestURI="${url}"
                                  requestURIcontext="true" >
                    <displaytag_el:column property="name" sortable="false" sortName="name" title="Name" />
                    <displaytag_el:column property="description" sortable="false" sortName="description" title="Description"/>
                    <displaytag_el:column title="Actions">
                        <jsecurity:hasPermission name="space:viewPageAsWiki:${favouritePagesTableElement.space.id}">
                        <stripes:link class="_view" beanclass="foo.bar.wiki.web.action.page.PageActionBean" event="view" name="favouritePages_view_${favouritePagesTableElement.name}">
                            <stripes:param name="page" value="${favouritePagesTableElement.id}"/>
                            View
                        </stripes:link>
                        </jsecurity:hasPermission>
                        <foobarwiki:hasAnyPermissions name="space:editPage:${favouritePagesTableElement.space.id}|space:viewPage:${favouritePagesTableElement.space.id}|space:removePage:${favouritePagesTableElement.space.id}">
                        |<stripes:link class="_edit" beanclass="foo.bar.wiki.web.action.page.EditPageActionBean" event="view" name="favouritePages_manage_${favouritePagesTableElement.name}">
                            <stripes:param name="currentPage" value="${favouritePagesTableElement.id}"/>
                            Manage
                        </stripes:link>
                        </foobarwiki:hasAnyPermissions>
                        <jsecurity:hasPermission name="space:viewPageAsWiki:${favouritePagesTableElement.space.id}">
                        |&nbsp;<stripes:link beanclass="foo.bar.wiki.web.action.general.PageFeedsActionBean" event="view" name="favouritePages_rss_${favouritePagesTableElement.name}">
                            <stripes:param name="feedType" value="rss_2_0"/>
                            <stripes:param name="page" value="${favouritePagesTableElement.id}"/>
                            RSS
                        </stripes:link>
                        |&nbsp;<stripes:link beanclass="foo.bar.wiki.web.action.general.PageFeedsActionBean" event="view" name="favouritePages_atom_${favouritePagesTableElement.name}">
                            <stripes:param name="feedType" value="atom_1_0"/>
                            <stripes:param name="page" value="${favouritePagesTableElement.id}"/>
                            ATOM
                        </stripes:link>
                        </jsecurity:hasPermission>
                    </displaytag_el:column>
                </displaytag:table>
        </div>
    </stripes:layout-component>
</stripes:layout-render>

